#ifndef USERMGR_H
#define USERMGR_H
#include<QObject>
#include"global.h"
#include"Singleton.h"
#include"userdata.h"
#include<QJsonArray>
class UserMgr:public QObject,public Singleton<UserMgr>,public std::enable_shared_from_this<UserMgr>
{
    Q_OBJECT
public:
    friend class Singleton<UserMgr>;
    ~UserMgr();
    void setName(QString name);
    void setUid(int uid);
    void setToken(QString token);
    QString GetName();
    int GetUid();
    QString GetIcon();
    std::shared_ptr<UserInfo>GetUserInfo();
    void AppendApplyList(QJsonArray array);
    void AppendFriendList(QJsonArray array);
    std::vector<std::shared_ptr<ApplyInfo>> GetApplyList();
    void AddApplyList(std::shared_ptr<ApplyInfo> app);
    void SetUserInfo(std::shared_ptr<UserInfo>user_info);
    bool AlreadyApply(int uid);
    bool CheckFriendById(int uid);
    void AddFriend(std::shared_ptr<AuthRsp>auth_rsp);
    void AddFriend(std::shared_ptr<AuthInfo>auth_info);
    void AppendFriendChatMsg(int friend_id,std::vector<std::shared_ptr<TextChatData> > msgs);
    std::shared_ptr<FriendInfo>GetFriendById(int uid);

    std::vector<std::shared_ptr<FriendInfo>> GetChatListPerPage();
    bool IsLoadChatFin();
    void UpdateChatLoadedCount();
    std::vector<std::shared_ptr<FriendInfo>> GetConListPerPage();
    void UpdateContactLoadedCount();
    bool IsLoadConFin();

private:
    UserMgr();    
    QString _name;
    QString _token;
    int _uid;
    std::vector<std::shared_ptr<ApplyInfo>>_apply_list;
    std::shared_ptr<UserInfo>_user_info;
    QMap<int,std::shared_ptr<FriendInfo>>_friend_map;
    std::vector<std::shared_ptr<FriendInfo>>_friend_list;
    int _chat_loaded;
    int _contact_loaded;
};

#endif // USERMGR_H
